package client.comm.baoding.dialog;


import android.content.Context
import android.view.View
import client.comm.baoding.R
import client.comm.baoding.databinding.DialogCommimgBinding
import client.comm.commlib.base.BaseActivity
import client.comm.commlib.base.SyBannerAdapter
import client.comm.commlib.comm_ui.bean.CommImg
import client.tzstore.oo.dialog.CenterDialog
import com.youth.banner.listener.OnBannerListener

class CommImgDialog(private val activity:  BaseActivity<*, *>) :
    CenterDialog<DialogCommimgBinding>(activity) {

    override fun getV(): Int {
        return R.layout.dialog_commimg
    }

    lateinit var commImg: CommImg

    override fun onBackPressed() {
    }

    var status: Int = -1
    override fun postBinding() {
        binding.event = this
        setCanceledOnTouchOutside(false)
        binding.banner.setAdapter(object : SyBannerAdapter<CommImg.Img>(commImg.img_list) {
            override fun onBindView(
                holder: BannerViewHolder?,
                data: CommImg.Img?,
                position: Int,
                size: Int
            ) {
                activity.mImgLoader.load(data?.small_img).into(
                    holder!!.imageView
                )
            }
        })

        binding.banner.setOnBannerListener(object : OnBannerListener<CommImg.Img> {
            override fun OnBannerClick(data: CommImg.Img?, position: Int) {
                click?.invoke(data!!)

            }
        })
        binding.banner.start()
        if (status == 1) {
            binding.closeImg.visibility = View.GONE
        } else if (status == 0) {
            binding.closeImg.visibility = View.VISIBLE

        }
    }

    var click: ((commImg: CommImg.Img) -> Unit)? = null


}